﻿@using PlatformNetCore.Entity
@{
    ViewBag.Title = "邮件服务配置";
}
@model SmtpConfig

<div style="padding: 15px;">
    <!-- 内容主体区域 -->
    <div class="layui-card">
        <div class="layui-card-header">邮件服务配置</div>
        <div class="layui-card-body">
            <form class="layui-form" id="applyForm" action="#" lay-filter="apply-form">
                <div class="layui-form-item">
                    <label class="layui-form-label">Smtp主机：</label>
                    <div class="layui-input-block">
                        <input type="hidden" id="ID" name="ID" autocomplete="on" value="@Model.ID" />
                        <input type="text" id="SmtpHost" name="SmtpHost" value="@Model.SmtpHost" placeholder="Smtp主机" autocomplete="on" class="layui-input" />
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">账号：</label>
                    <div class="layui-input-block">
                        <input type="text" id="Account" name="Account" value="@Model.Account" placeholder="账号" autocomplete="on" class="layui-input" />
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">密码：</label>
                    <div class="layui-input-block">
                        <input type="password" id="Pwd" name="Pwd" value="@Model.Pwd" placeholder="密码" autocomplete="on" class="layui-input" />
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">端口：</label>
                    <div class="layui-input-block">
                        <input type="text" id="Port" name="Port" value="@Model.Port" placeholder="端口" autocomplete="on" class="layui-input" />
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">是否SSL</label>
                    <div class="layui-input-block">
                        <input type="checkbox" checked="" name="IsSSL" value="@Model.IsSSL" lay-skin="switch" lay-filter="ssl-Switch" lay-text="是|否">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">联系接收邮箱：</label>
                    <div class="layui-input-block">
                        <input type="text" id="Email" name="Email" value="@Model.Email" placeholder="联系接收邮箱" autocomplete="on" class="layui-input" />
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-input-block">
                        <button type="button" class="layui-btn" id="btnSubmit" lay-submit lay-filter="submit-form">保存</button>
                    </div>
                </div>
            </form>
        </div>
    </div>
</div>
@section Scripts
    {
    <script>
    layui.use(['form', 'layer'], function () {
        var layer = layui.layer, form = layui.form;

        form.render(null, 'apply-form');

        /* 监听指定开关 */
        form.on('switch(ssl-Switch)', function (data) {
            $(this).val(this.checked ? '1' : '0')
        });

        form.on('submit(submit-form)', function (data) {

            //询问框
            layer.confirm('确认保存吗？', {
                btn: ['确定', '关闭'], //按钮
                title: '提示'
            }, function () {
                //禁用
                $("#btnSubmit").attr("disabled", true);
                var paras = data.field;
                var loadingFlag;
                $.ajax({
                    url: "/Admin/Basis/SmtpConfig",
                    type: "POST",
                    data: paras,
                    beforeSend: function () {
                        //注意，layer.msg默认3秒自动关闭，如果数据加载耗时比较长，需要设置time
                        loadingFlag = layer.msg('正在处理，请稍候……', { icon: 16, shade: 0.01, shadeClose: false, time: 15000 });
                    },
                    success: function (response) {
                        //启用
                        layer.close(loadingFlag);
                        if (response.success) {
                            //保存成功
                            layer.msg('保存成功', { icon: 1, time: 1500 }, function () {
                                $("#btnSubmit").removeAttr("disabled");
                                window.location.href = "@Url.Action("SmtpConfig", "Basis",new { area = "Admin"})";
                            });
                        } else {
                            $("#btnSubmit").removeAttr("disabled");
                            layer.msg(response.msg, { icon: 2, time: 5000 });
                        }
                    },
                    complete: function () {
                        layer.close(loadingFlag);
                    }
                });
            });
        });
    });
    </script>
}
